from utils import getText

from member_function import DoxygenMemberFunction

class DoxygenClass:
    def __init__(self, xml):
        self.refid = xml.attributes["refid"].value
        self.name = getText(xml.getElementsByTagName("name")[0].childNodes)

        self.member_funcs = [DoxygenMemberFunction(node) for node in xml.getElementsByTagName("member") if node.attributes["kind"].value == "function"]

    def createCode(self, prefix):
        if len(self.member_funcs) == 0:
            memberfuncs = ""
        else:
            memberfuncs = "== Public Member Functions ==\n"
            for f in self.member_funcs:
                memberfuncs += "  * %(name)s\n" % {"name": f.name, }

        code = """#summary Automatically Generated by Doxygen2gwiki

= Class %(name)s =

%(memberfuncs)s

""" % ({"name": self.name, "memberfuncs": memberfuncs})
        return (prefix + self.refid + ".wiki", code)
